{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Using the missing_inds function to label interpolated values\n\nIf you have data with missing values, Hypertools will try to interpolate them\nusing PPCA.  To visualize how well its doing, you can use the missing_inds\nfunction and then highlight the values that were interpolated.  Here, we\ngenerated some synthetic data, removed some values, and then plotted the\noriginal data, data with missing values and highlighted the missing datapoints\nwith stars.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# Code source: Andrew Heusser\n# License: MIT\n\n# import\nfrom scipy.linalg import toeplitz\nimport numpy as np\nfrom copy import copy\nimport hypertools as hyp\n\n# simulate data\nK = 10 - toeplitz(np.arange(10))\ndata1 = np.cumsum(np.random.multivariate_normal(np.zeros(10), K, 250), axis=0)\ndata2 = copy(data1)\n\n# randomly remove 5% of the data\nmissing = .01\ninds = [(i,j) for i in range(data1.shape[0]) for j in range(data1.shape[1])]\nmissing_data = [inds[i] for i in np.random.choice(int(len(inds)), int(len(inds)*missing))]\nfor i,j in missing_data:\n    data2[i,j]=np.nan\n\n# reduce the data\ndata1_r,data2_r = hyp.reduce([data1, data2], ndims=3)\n\n# pull out missing inds\nmissing_inds = hyp.tools.missing_inds(data2)\nmissing_data = data2_r[missing_inds, :]\n\n# plot\nhyp.plot([data1_r, data2_r, missing_data], ['-', '--', '*'],\n         legend=['Full', 'Missing', 'Missing Points'])"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.12.4"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}